<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:pe="http://primefaces.org/ui/extensions">

    <h:body>

        <ui:composition template="/resources/template/template.xhtml">

            <ui:define name="content">
                <h:form>
                    <p:panel header="OPD Membership Discount Matrix" id="reportPrint">

                        <p:panel header="Add new Matrix" >
                            <p:panelGrid columns="2" >
                                <h:outputLabel value="Membership Scheme"/>
                                <p:autoComplete forceSelection="true" 
                                                value="#{opdMemberShipDiscountController.membershipScheme}" 
                                                completeMethod="#{membershipSchemeController.completeMembershipScheme}" 
                                                var="mem" itemLabel="#{mem.name}" itemValue="#{mem}" >
                                </p:autoComplete>
                                <h:outputLabel value="Category/Subcategory" ></h:outputLabel>
                                <p:autoComplete value="#{opdMemberShipDiscountController.category}" 
                                                forceSelection="true"
                                                completeMethod="#{categoryController.completeCategoryServiceInvestigation}"
                                                converter="categoryConverter"
                                                var="cat" itemLabel="#{cat.name} #{cat.parentCategory}" itemValue="#{cat}" >
                                    <p:column headerText="Category">
                                        <h:outputLabel value="#{cat.name}"/>
                                    </p:column>
                                    <p:column headerText="Parent Category">
                                        <h:outputLabel value="#{cat.parentCategory.name}"/>
                                    </p:column> 
                                    <p:column headerText="TYPE">
                                        <h:outputLabel value="Parent Category" 
                                                       rendered="#{cat.categoryClass eq 'class com.divudi.entity.ServiceCategory'}"/>
                                        <h:outputLabel value="Child Category" 
                                                       rendered="#{cat.categoryClass eq 'class com.divudi.entity.ServiceSubCategory'}"/>
                                        <h:outputLabel value="Investigation Category" 
                                                       rendered="#{cat.categoryClass eq 'class com.divudi.entity.InventoryCategory'}"/>
                                    </p:column> 
                                </p:autoComplete>

                                <h:outputLabel value="Payment Method"/>
                                <p:selectOneMenu   value="#{opdMemberShipDiscountController.paymentMethod}"  >
                                    <f:selectItem itemLabel="Select" />                           
                                    <f:selectItems value="#{enumController.paymentMethods}" />                                    
                                </p:selectOneMenu>
                                <h:outputLabel value="Discount" ></h:outputLabel>
                                <p:inputText autocomplete="off" value="#{opdMemberShipDiscountController.margin}" />
                                <h:outputLabel value="" ></h:outputLabel>
                                <p:commandButton id="btnAdd" value="Add" ajax="false"
                                                action="#{opdMemberShipDiscountController.saveOpdCategory()}" >
                                </p:commandButton>

                                <p:defaultCommand target="btnAdd"/>
                            </p:panelGrid>
                            <p:commandButton ajax="false" value="Excel" styleClass="noPrintButton" style="float: right;" >
                                <pe:exporter type="xlsx" target="inwd" fileName="Price_metrix_investigation"  />
                            </p:commandButton>
                            <p:commandButton ajax="false" value="Fill"
                                            action="#{opdMemberShipDiscountController.createItemsCategoryOpd()}" />
                            <p:commandButton ajax="false" value="Print" styleClass="noPrintButton" >                                         
                                <p:printer target="reportPrint"/>
                            </p:commandButton>

                        </p:panel>

                        <p:panel header="Price Matrix" >

                            <p:dataTable id="inwd" value="#{opdMemberShipDiscountController.items}"
                                         filteredValue="#{opdMemberShipDiscountController.filterItems}"
                                         var="a" editable="true" scrollable="true" scrollHeight="500">

                                <p:column headerText="Member Ship Scheme">
                                    <p:autoComplete forceSelection="true" 
                                                    value="#{a.membershipScheme}" 
                                                    completeMethod="#{membershipSchemeController.completeMembershipScheme}" 
                                                    var="mem" itemLabel="#{mem.name}" itemValue="#{mem}" >
                                    </p:autoComplete>
                                </p:column>

                                <p:column headerText="Category Name"
                                          filterBy="#{a.category.name}" filterMatchMode="contains">
                                    <p:autoComplete forceSelection="true" value="#{a.category}"
                                                    completeMethod="#{categoryController.completeCategoryInvestigation}" 
                                                    converter="categoryConverter"
                                                    var="cat" itemLabel="#{cat.name}" itemValue="#{cat}" >
                                        <p:column>
                                            <h:outputLabel value="#{cat.name}"/>
                                        </p:column>
                                        <p:column>
                                            <h:outputLabel value="#{cat.parentCategory.name}"/>
                                        </p:column> 
                                        <p:column headerText="TYPE">
                                            <h:outputLabel value="Parent Category" 
                                                           rendered="#{cat.categoryClass eq 'class com.divudi.entity.ServiceCategory'}"/>
                                            <h:outputLabel value="Child Category" 
                                                           rendered="#{cat.categoryClass eq 'class com.divudi.entity.ServiceSubCategory'}"/>
                                            <h:outputLabel value="Investigation Category" 
                                                           rendered="#{cat.categoryClass eq 'class com.divudi.entity.InventoryCategory'}"/>
                                        </p:column> 
                                    </p:autoComplete>
                                </p:column>

                                <p:column headerText="Payment Method">
                                    <p:selectOneMenu  value="#{a.paymentMethod}"  >
                                        <f:selectItem itemLabel="Select" />                           
                                        <f:selectItems value="#{enumController.paymentMethods}" />                                    
                                    </p:selectOneMenu>
                                </p:column>

                                <p:column  headerText="Discount">
                                    <h:inputText autocomplete="off" value="#{a.discountPercent}" >
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:inputText>
                                </p:column>
                                <p:column>
                                    <p:commandButton ajax="false" value="Update" action="#{opdMemberShipDiscountController.onEdit(a)}"/> 
                                </p:column>
                                <p:column>
                                    <p:commandButton value="Delete" action="#{opdMemberShipDiscountController.deleteCategoryOpd}">
                                        <f:setPropertyActionListener value="#{a}" target="#{opdMemberShipDiscountController.current}"/>
                                    </p:commandButton>
                                </p:column>

                            </p:dataTable>


                        </p:panel>

                    </p:panel>

                </h:form>
            </ui:define>


        </ui:composition>

    </h:body>
</html>
